<template>
  <div>
    <h1>参与拼团</h1>
    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="joinId" label="参与ID" />
        <el-table-column prop="joinName" label="拼团活动名称" />
        <el-table-column prop="joinTip" label="活动简介" />
        <el-table-column prop="prodUnit" label="商品单位" />
        <el-table-column prop="" label="商品轮播图">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <el-image
                :src="scope.row.joinImages"
                style="width: 50px; height: 50px"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="beginTime" label="活动开始时间" />
        <el-table-column prop="endTime" label="活动截止时间" />
        <el-table-column prop="groupNum" label="拼团人数" />
        <el-table-column prop="buyMax" label="购买数量" />
        <el-table-column prop="virtualNum" label="补齐人数" />
        <el-table-column prop="prodInfoId" label="拼团商品" />
        <el-table-column prop="sendKind" label="配送方式" />
        <el-table-column prop="sendMoney" label="运费" />
        <el-table-column prop="joinDesc" label="活动详情" />
        <el-table-column prop="createdTime" label="创建时间" />
        <el-table-column label="操作"> </el-table-column>
      </el-table>
      <div class="demo-pagination-block">
        <el-pagination
          v-model:current-page="searchForm.pageNum"
          v-model:page-size="searchForm.pageSize"
          :page-sizes="[2, 4, 6, 8]"
          :size="size"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { selectJoinList } from "../api/active";
import type { ComponentSize } from "element-plus";

const tableData = ref([]);
const searchForm = ref({
  pageNum: 1,
  pageSize: 2,
});
const total = ref(0);

const size = ref<ComponentSize>("default");
const background = ref(false);
const disabled = ref(false);

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};
const loadList = () => {
  selectJoinList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};

onMounted(() => {
  loadList();
});
</script>

<style scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>
